package com.example.myspringframework.context.event;

import com.example.myspringframework.context.ApplicationEvent;
import com.example.myspringframework.context.ApplicationListener;

import java.util.HashSet;
import java.util.Set;

/**
 * 事件发布者底层实现
 * 仅实现了添加了删除监听器
 */
public abstract class AbstractApplicationEventMulticaster implements ApplicationEventMulticaster {
    public final Set<ApplicationListener<ApplicationEvent>> applicationListeners = new HashSet<>();

    /**
     * 添加监听器
     */
    @Override
    public void addApplicationListener(ApplicationListener<?> listener) {
        this.applicationListeners.add((ApplicationListener<ApplicationEvent>) listener);
    }

    /**
     * 删除监听器
     */
    @Override
    public void removeApplicationListener(ApplicationListener<?> listener) {
        this.applicationListeners.remove(listener);
    }
}
